home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Grafik / Paint / ArtEffect4 / Rexx / process-dir.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-05-28  |  8.4 KB  |  257 lines

  1. /*
  2.                 Process-Dir.rexx
  3.  
  4.                 Example script that applies a plugin-effect to all files of a
  5.                 directory
  6.  
  7.                 Refer to ArtEffect:Rexx/Rexx.doc for a complete command
  8.                 description
  9.  
  10.                 Attention: filenames must not include any blank spaces!
  11. */
  12.  
  13. OPTIONS RESULTS
  14. OPTIONS FAILAT 21
  15. SIGNAL ON ERROR
  16.  
  17. /* Check for ArtEffect ARexx port */
  18. IF ~SHOW(P,"ArtEffect") THEN DO
  19.         SAY D2C(7)
  20.         SAY "ATTENTION:"
  21.         SAY "Could not find ArtEffect ARexx port."
  22.         SAY "Please make sure that ArtEffect is running."
  23.         SAY
  24.         EXIT
  25. END
  26.  
  27. ADDRESS "ArtEffect"
  28.  
  29. /* check for rexxsupport.library (necessary for ShowDir) */
  30. IF ~SHOW('L', "rexxsupport.library") THEN
  31.         IF ~ADDLIB('rexxsupport.library', 0, -30) THEN DO
  32.                 REQUESTNOTIFY TITLE '"System error"' PROMPT '"rexxsupport.library
  33.                 could not be opened"'
  34.                 EXIT 10
  35.         END
  36.  
  37. /* Filerequester - get a list of all files to be processed */
  38. REQUESTFILE VAR filterdir PATH "ArtEffect:" TITLE '"Choose directory"' DIR
  39. IF ~RC = 0 THEN REQUESTNOTIFY TITLE '"An error has occured"' PROMPT '"You cancelled the requester"'
  40.  
  41. filelist = ShowDir(filterdir, FILE,)
  42.  
  43. REQUESTRESPONSE VAR inplace TITLE '"Please select..."' PROMPT '"Do you want to save the modified pictures|over the original ones?"' OPTIONS "Yes|No"
  44.  
  45. IF inplace = 1 THEN REQUESTFILE VAR savepath TITLE '"Choose directory"' DIR
  46.  
  47. /* keep user from interfering */
  48. LOCKGUI
  49.  
  50. /* repeat loop until all files have been processed */
  51. DO WHILE ~(Compress(filelist) = "")
  52.  
  53.         /* get name of file to be processed */
  54.         currfile = SubWord(filelist, 1, 1)
  55.  
  56.         /* attach full path to filename */
  57.         picpath = filterdir || currfile
  58.  
  59.         /* load the picture */
  60.         LOADPIC picpath
  61.  
  62.         /* change this to the desired plugin */
  63.         DOMETHOD QUIT 'POINTISE'
  64.  
  65.         IF inplace = 0 THEN SAVEPIC NAME picpath PLUGIN 'JFIF-JPEG' /* insert
  66.         desired save format here */
  67.                 ELSE DO
  68.                         picpath = savepath || currfile
  69.                         SAVEPIC NAME picpath PLUGIN 'JFIF-JPEG' /* insert desired save
  70.                         format here */
  71.                 END
  72.  
  73.         /* close the picture */
  74.         CLOSEPIC FORCE
  75.  
  76.         /* remove the file that was just processed from the list of files
  77.         still to be processed */
  78.         filelist = SubStr(filelist, Length(currfile)+2)
  79. END
  80.  
  81. /* Tell the user everything went fine */
  82. REQUESTNOTIFY TITLE '"User information"' PROMPT "All pictures were
  83. processed successfully."
  84.  
  85. /* return control to user - NEVER forget this! */
  86. UNLOCKGUI
  87.  
  88. EXIT
  89.  
  90. /* this function is executed when an error occurs in the script */
  91. ERROR:
  92.         /* tell the user in which line of this script to look for the error */
  93.         REQUESTNOTIFY TITLE '"ARexx-Error"' PROMPT "ARexx-error no." RC " has occured in line" SIGL "."
  94.  
  95.         /* do not forget to unlock the GUI */
  96.         UNLOCKGUI
  97.  
  98. EXIT
  99.  
  100.  
  101. /******************************************************************/
  102. /*                                                                */
  103. /*                VAnim.rexx V1.1 for ArtEffect 2.5.x             */
  104. /*                                                                */
  105. /* This rexxscript assembles a series of pictures to form a       */
  106. /* TransferAnim for Voyager or IBrowse.                           */
  107. /*                                                                */
  108. /* Written by: Eike M. Lang <elang@online-club.de>                */
  109. /* Homepage:   http://jayhawk.home.pages.de/                      */
  110. /*                                                                */
  111. /* Usage: create a number of pictures of equal size that will be  */
  112. /* the frames of the animation.  These pictures must be numbered  */
  113. /* consistently.                                                  */
  114. /* The name format for the frames MUST be <filename>.xxxx         */
  115. /* Where xxxx can be anything between 0000 and 9999               */
  116. /* <filename> can be any AmigaDOS-legal file name.                */
  117. /* Run the script from the shell or directly from ArtEffect.      */
  118. /* You can freely choose the start- and end-frames, but naturally */
  119. /* all frames in between those should exist.                      */
  120. /* Once the animation is assembled you are given the choice of    */
  121. /* saving it immediately.                                         */
  122. /*                                                                */
  123. /* The script tries to cover all common error-situations, but if  */
  124. /* you try hard enough, you'll still be able to mess it up.       */
  125. /* So don't get fancy and try to use anim-frames of different     */
  126. /* sizes (which would also look funny in Voyager and IBrowse) and */
  127. /* don't try to use your C sources or anything like that as anim  */
  128. /* frames.                                                        */
  129. /*                                                                */
  130. /* This script is freeware which means I retain full copyright    */
  131. /* on it. Permission is granted to Haage&Partner GmbH to include  */
  132. /* this script with ArtEffect.                                    */
  133. /*                                                                */
  134. /******************************************************************/
  135.  
  136. OPTIONS RESULTS
  137. OPTIONS FAILAT 21
  138. SIGNAL ON ERROR
  139.  
  140. /* Check for ArtEffect ARexx port */
  141. IF ~SHOW(P,"ArtEffect") THEN DO
  142.         SAY D2C(7)
  143.         SAY "ATTENTION:"
  144.         SAY "Could not find ArtEffect ARexx port."
  145.         SAY "Please make sure that ArtEffect is running."
  146.         SAY
  147.         EXIT
  148. END
  149.  
  150. ADDRESS "ArtEffect"
  151.  
  152.  
  153.  
  154. /* keep the user from interfering */
  155. LOCKGUI
  156.  
  157. /* Find out path and name of the first and last picture */
  158. REQUESTFILE VAR firstfile TITLE '"Select the first picture"'
  159. picpath=Left(firstfile, LastPos('/',firstfile))
  160. REQUESTFILE VAR lastfile PATH picpath TITLE '"Select the last picture"'
  161.  
  162. /* Load the last picture to be used */
  163. LOADBRUSH lastfile
  164. IF RC~=0 THEN
  165.         CALL NOTIFY("File" lastfile "could not be found.")
  166.  
  167. /* get width/height of the frames */
  168. GET STEM brush. BRUSHINFO
  169.  
  170. /* assign some variables we need */
  171. /* This is the base name of the variable without the number extension */
  172. stemname=Left(firstfile, Pos('.', firstfile))
  173.  
  174. /* This is the number of the first image to use */
  175. startnumber=Right(firstfile, Length(firstfile)-LastPos('.', firstfile))
  176.  
  177. /* This is the number of the last image to use */
  178. endnumber=Right(lastfile, Length(lastfile)-LastPos('.', lastfile))
  179.  
  180. /* Now calculate the total width of the animation */
  181. totalwidth=brush.width*(endnumber-startnumber+1)
  182.  
  183. /* Sanity check */
  184. IF totalwidth<1 THEN
  185.         NOTIFY("The last file must have a greater|number than the first one.")
  186.  
  187. /* Generate a new project with the right size */
  188. NEW WIDTH totalwidth HEIGHT brush.height NAME "TransferAnim"
  189.  
  190. /* Main loop */
  191. DO i=0 TO (endnumber-startnumber)
  192.  
  193.         /* calculate the current file for this cycle */
  194.         currfile=stemname || Right(i+startnumber, 4, 0)
  195.  
  196.         /* attempt to load it */
  197.         LOADBRUSH currfile
  198.  
  199.         /* Check existence of each file */
  200.         IF RC~=0 THEN
  201.                 CALL NOTIFY("File" currfile "could not be found.|Please make sure all files between|" firstfile "and" lastfile "exist.")
  202.  
  203.         /* Make position caculation as easy as possible */
  204.         CHANGEBRUSH HANDLE TOPLEFT
  205.  
  206.         /* Finally put the image on the page */
  207.         PLOT i*brush.width 0 PT PEN MODE MATTE STR 100
  208. END
  209.  
  210. /* Give the user the chance to save his creation right away */
  211. REQUESTRESPONSE VAR choice TITLE '"User Query"' PROMPT '"Do you want to save this animation?"' OPTIONS "Yes|No|Don't Know"
  212.  
  213. /* Save-file feat. full(?) sanity-check */
  214. IF choice=0 THEN DO
  215.         REQUESTFILE VAR saveanim TITLE '"Save Animation"' FILE "TransferAnim"
  216.         SAVE
  217.         IF RC~=0 THEN
  218.                 CALL NOTIFY("You cancelled the saving process.")
  219.         SAVEPIC NAME saveanim PLUGIN IFF-ILBM
  220.         IF RC~=0 THEN
  221.                 CALL NOTIFY("File" savenanim "could not be saved.")
  222. END
  223.  
  224. /* Notify user that he can save the file at a later time */
  225. ELSE REQUESTNOTIFY TITLE "Message" OK '"I see"' PROMPT "You can still save the|animation manually."
  226.  
  227. /* return control to user */
  228. UNLOCKGUI
  229.  
  230. EXIT
  231.  
  232. /* Error notification - saves a few lines of rexx code */
  233. NOTIFY:
  234.         /* Get the actual error */
  235.         PARSE ARG Errorstring
  236.  
  237.         /* Notify user via the ArtEffect-provided requester */
  238.         REQUESTNOTIFY TITLE "Error" PROMPT Errorstring
  239.  
  240.         /* always make sure the GUI is unlocked after errors */
  241.         UNLOCKGUI
  242.         EXIT
  243. RETURN
  244.  
  245. /* Handling of errors that are not intercepted by the script itself
  246.      The most common situation for this message to appear is that the
  247.      user did not follow the naming conventions for the frames.
  248.      This error will of course also occur when trying to load files of
  249.      the wrong format - ASCII, binaries, etc. ;-) */
  250.  
  251. ERROR:
  252.         REQUESTNOTIFY TITLE "ARexx-Error" PROMPT "ARexx-error no." RC "has occured in line" SIGL ".|Please make sure the pictures are properly named|and numbered."
  253.         UNLOCKGUI
  254. EXIT
  255.  
  256.  
  257.